// EnvironmentSensor.java
package com.smartfarm.observer;

import java.util.ArrayList;
import java.util.List;

public class EnvironmentSensor implements Subject {
    private List<Observer> observers = new ArrayList<>();

    public void registerObserver(Observer o) {
        observers.add(o);
    }

    public void notifyObservers(String event) {
        for (Observer o : observers) {
            o.update(event);
        }
    }

    public void sensorUpdate(String event) {
        System.out.println("\n[传感器检测到] " + event);
        notifyObservers(event);
    }
}